$(document).ready(function() {
	$("#upfile").change(function() {
		var orimg = $("#update-thumb").attr("src");
		$("#update-thumb").attr("src", "images/pam/loading.gif");
		$.ajaxFileUpload({
			url : "uploadFile.do",
			secureuri : false,
			fileElementId : "upfile",
			dataType : "xml",
			success : function(data) {
				var xml = data.childNodes;
				var root = xml[0];
				var items = root.childNodes;
				var item = items[0];
				
				if (item.nodeName == "data") {
					var path = item.firstChild.nodeValue;
					if (path != undefined) {
						$("#update-thumb").attr("src", path);
						$("#update-thumb").parent().next().html("");
					}
				}
				else {
					if (item.nodeName == "error") {
						$("#update-thumb").parent().next().html(getMessage("error", item.firstChild.nodeValue));
					}
					else {
						$("#update-thumb").parent().next().html(getMessage("error", "Cannot upload the image!"));
					}
					$("#update-thumb").attr("src", orimg);
				}
			},
			error : function(xhr, testStatus, error) {
				$("#update-thumb").parent().next().html(getMessage("error", "Cannot upload the image!"));
				$("#update-thumb").attr("src", orimg);
				return;
			}
		});
	});
});